package com.qf.ithub.movie_demo01.service.impl;


import com.qf.ithub.movie_demo01.entity.Movie;
import com.qf.ithub.movie_demo01.entity.MovieExample;
import com.qf.ithub.movie_demo01.mapper.MovieMapper;
import com.qf.ithub.movie_demo01.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author : xixi
 * @Title :
 * @date :  2021-03-15 20:22
 */
@Service
public class MovieServiceImpl implements MovieService {

    @Autowired
    private MovieMapper movieMapper;

    @Override
    public List<Movie> getNowPlaying() {
        //获得当前时间
        Date now = new Date();
        MovieExample example = new MovieExample();
        example.createCriteria().andReleasetimeLessThan(now).andUnderoftimeGreaterThan(now);
        List<Movie> movies = movieMapper.selectByExample(null);
        return movies;
    }

    @Override
    public List<Movie> getSoonPlaying() {
        //获得当前时间
        Date date1 = new Date();
        //获得结束的时间
        Calendar calendar =Calendar.getInstance();
        calendar.setTime(date1);
        calendar.add(calendar.DAY_OF_MONTH,15);

        Date date2 = calendar.getTime();
        MovieExample example = new MovieExample();
        //example.createCriteria().andReleaseBetween(date1,date2);
        example.createCriteria().andReleasetimeBetween(date1,date2);
        List<Movie> movies = movieMapper.selectByExample(example);
        return movies;
    }
}
